package cn.com.code.design;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * Mq 适配器
 * @author zhengpei
 * @date 2021/9/19
 */
public class MqAdapter {
  public static RebateInfo filter(String strJson, Map<String, String> link) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    return filter(JSON.parseObject(strJson, Map.class), link);
  }

  public static RebateInfo filter(Map obj, Map<String, String> link) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    RebateInfo rebateInfo = new RebateInfo();
    for (String key : link.keySet()) {
      Object val = obj.get(link.get(key));
      RebateInfo.class.getMethod("set" + key.substring(0, 1).toUpperCase() + key.substring(1), String.class).invoke(rebateInfo, val.toString());
    }
    return rebateInfo;
  }

}
